<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <input type="file" name="" id="file" multiple />
    <span class="progress-bar"></span>
    <span class="progress-bar"></span>
    <span class="progress-bar"></span>
    <script>
        var oFile = document.getElementById('file')
        oFile.onchange = function() {
            var files = oFile.files,
                fileLen = files.length;
            if (fileLen <= 0) {
                console.log('您还没有选择图片');
                return
            }
            if (fileLen > 3) {
                console.log('每次最多上传3张');
                return
            }
            for (let i = 0; i < fileLen; i++) {
                let fd = new FormData()
                fd.append('file', files[i])
                var o = window.XMLHttpRequest ? new window.XMLHttpRequest() : new ActiveXObject('Microsoft.XMLHTTP')
                o.open('post', 'https://localhost:8081/manage/writeArticle')
                o.upload.onprogress = function(e) {
                    console.log('111');
                    var e = e | window.event,
                        percent = e.loaded / e.total * 100 + '%',
                        thisProgressBar = document.getElementsByClassName('progress-bar')[i]
                    thisProgressBar.innerHTML = percent
                }
                o.send(fd)
            }

        }
    </script>
</body>

</html>